import { Component, Injector } from '@angular/core';
import { AppComponentBase } from '@abp/components';
import {
  WeChatMiniProgramSettingsEditDto,
  MiniProgramSettingsServiceProxy,
  MiniProgramSettingsEditDto,
} from '@abp/service-proxies/service-proxies';

@Component({
  templateUrl: './mini-program-settings.component.html',
  styleUrls: ['./mini-program-settings.component.less'],
})
export class MiniProgramSettingComponent extends AppComponentBase {
  wechatMiniProgram = new WeChatMiniProgramSettingsEditDto();
  constructor(
    injector: Injector,
    private miniProgramSettingService: MiniProgramSettingsServiceProxy,
  ) {
    super(injector);
  }

  ngOnInit(): void {
    this.miniProgramSettingService.getAllSettings().subscribe(setting => {
      this.wechatMiniProgram = setting.weChatMiniProgram;
    });
  }

  submitForm() {
    let miniprogramSetting = new MiniProgramSettingsEditDto();
    miniprogramSetting.weChatMiniProgram = this.wechatMiniProgram;
    this.miniProgramSettingService
      .updateAllSettings(miniprogramSetting)
      .subscribe(result => {
        this.notify.success('保存成功！');
      });
  }
}
